package com.success.application.user;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.success.application.base.BaseFragment;
import com.success.application.base.BaseTitleFragment;
import com.success.application.myapplication.R;
import com.success.application.user.activity.LoginActivity;
import com.success.application.user.activity.UserMessageActivity;
import com.success.application.user.bean.User;

import butterknife.Bind;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by fei on 2016/8/15.
 * <p>
 * 用户个人界面
 */

public class UserInfoFragment extends BaseTitleFragment {

    @Bind(R.id.iv_portrait)
    CircleImageView mCirclePortrait;
//    @BindView(R.id.user_info_icon_container)
//    FrameLayout mFlUserInfoIconContainer;

    @Bind(R.id.tv_nick)
    TextView mTvName;
    @Bind(R.id.rl_show_my_info)
    LinearLayout mRlShowInfo;
    @Bind(R.id.rl_info_setting)
    LinearLayout msetting;
    public static final int REQUEST_CODE_USER_INFO = 1;
    public static final int REQUEST_CODE_LOGIN = 2;
    public static final int REQUEST_CODE_SETTING = 3;
//    @Override
//    protected int getLayoutId() {
//
//    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.user_fragment_home;
    }

    @Override
    protected int getTitleRes() {
        return R.string.index_me;
    }
    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
    }

//    @OnClick(R.id.iv_logo_setting)
//    void onSetting() {
//        Intent intent = new Intent(getActivity(), UserSettingActivity.class);
//        startActivityForResult(intent, REQUEST_CODE_SETTING);
//    }

    @Override
    protected void initData() {
        super.initData();
        User user = AccountHelper.getUser();
        if (TextUtils.isEmpty(user.getId())) {
            mTvName.setText("游客");
        } else {
            mTvName.setText(user.getUser_yhm());
        }
        if(user.getUser_tx()!=null){
                Glide.with(getContext()).load(user.getUser_tx()).into(mCirclePortrait);
        }else{
            mCirclePortrait.setImageResource(R.mipmap.logo);
        }
//        if(user.getSumJf()!= null){
//            mTvFollowCount.setText(user.getSumJf());
//        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    @OnClick(R.id.iv_portrait)
    void onProtrait(){
        if(AccountHelper.getUserId() != null) {
//            Intent intent = new Intent(getActivity(), UserInfoActivity.class);
//            startActivityForResult(intent, REQUEST_CODE_USER_INFO);
        } else {
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.putExtra("loginActivity", "loginActivity");
            startActivityForResult(intent, REQUEST_CODE_LOGIN);
            return;
        }
    }
    //点击设置
    @OnClick(R.id.rl_info_setting)
    void onSetting(){
        //点击先清除缓存
        AccountHelper.logout(msetting, new Runnable() {
            @SuppressLint("SetTextI18n")
            @Override
            public void run() {
//                finish();
            }
        });
    }

    //个人信息
    @OnClick(R.id.rl_geren_message)
    void onClickGerenMessage() {
        if (AccountHelper.getUserId() != null) {
            Intent intent = new Intent(getActivity(), UserMessageActivity.class);
            startActivityForResult(intent, REQUEST_CODE_USER_INFO);
        } else {
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.putExtra("loginActivity", "loginActivity");
            startActivityForResult(intent, REQUEST_CODE_LOGIN);
            return;
        }
    }
}
